home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / GRAPHICS.SWG / 0165_sprites w- virtual screen.pas < prev    next >
Pascal/Delphi Source File  |  1995-02-28  |  3KB  |  76 lines

  1. {The Following code is a little cheeze example of getting around the ye ol'
  2.  retrace and flicker problem. To do this all writes are made to a vitual
  3.  screen and then the whole thing is moved at once. This code has quite a
  4.  nice effect even though it almost all in pure pascal.
  5.  Enjoy: Swag ready. [g]}
  6. {$q-,r-,d-,b-}
  7. PROGRAM game_sprites;
  8. { Slow game-sprites-example, by Bas van Gaalen, Holland, PD }
  9. {12/20/94}
  10. { Modified and completely rewritten by Mr. Krinkle : Cameron Clark}
  11. USES crt;
  12. CONST  maxSpr=110;                         {Reduce, if program runs slugish}
  13.        ScrSze=64000;
  14. TYPE a_scrn= ARRAY [1..ScrSze] OF byte;
  15.      sprite= RECORD
  16.              xCOR,  yCOR   : word;
  17.              width, height : byte;
  18.              vVEL,  hVEL   : word;
  19.              it: ARRAY[1..500]  OF byte;   {bitmap}
  20.      END;
  21. VAR sprites : ARRAY[1..MaxSpr] OF sprite;
  22.     point1 : Pointer;
  23.     point2 : ^a_scrn; {Used for screen math}
  24.     i,j,k  : word;
  25. PROCEDURE setpal(col,r,g,b : byte); assembler; ASM
  26.   mov dx,03c8h; mov al,col; out dx,al; Inc dx; mov al,r
  27.   out dx,al; mov al,g; out dx,al; mov al,b; out dx,al; END;
  28.  
  29. PROCEDURE putsprite( VAR spriter : sprite );
  30. VAR i : word;
  31. BEGIN {Update coordinates according to H&V velocity and virtual draw}
  32.   WITH Spriter DO BEGIN
  33.    IF  (xCOR + hVEL > 320 - width)  OR (xCOR + hVEL < 1) THEN
  34.        hVEL:=hVEL * -1;
  35.    IF  (yCOR + vVEL > 200 - height) OR (yCOR + vVEL < 1) THEN
  36.        vVEL:=vVEL * -1;
  37.    xCOR:=xCOR + hVEL;  yCOR:=yCOR + vVEL;
  38.    FOR i:=0 TO (width * height)-1 DO
  39.        IF  it[i+1] <> 0 THEN
  40.        Point2^[(yCOR + (i DIV width)) * 320 +
  41.                 xCOR + (i MOD width)]:= it[i+1];
  42.   END;
  43. END;
  44.  
  45. BEGIN {*Skeleton*}
  46.   ASM mov ax,13h; Int 10h; END;
  47.   FOR i:=1 TO 255 DO setpal(i,255-i DIV 6,255-i DIV 4,50);
  48.  { create and save background }
  49.   FOR i:=0 TO (320*200)-1 DO mem[$a000:i]:=random(50)+200;
  50.   GetMem(Point1, ScrSze);
  51.   GetMem(point2, ScrSze);
  52.   Move(mem[$a000:0000], Point1^, ScrSze);
  53.   Randomize;  { create random sprite }
  54.   FOR J:=1 TO MaxSpr DO BEGIN
  55.       sprites[j].xCor := random(300)+1;  {Screen Pos}
  56.       sprites[j].yCor := random(170)+1;
  57.       sprites[j].width := random(15)+5;  {Dimensions}
  58.       sprites[j].height := random(15)+5;
  59.       sprites[j].hVEL := 6-random(16);   {horiz. sprite displacement}
  60.       sprites[j].vVEL := 6-random(13);   {Vert.  sprite displacement}
  61.       K:=random(5)+1;
  62.       FOR i:=1 TO sprites[j].width * sprites[j].height DO BEGIN
  63.           IF I DIV k = i / k THEN sprites[J].it[I]:= I MOD 255;
  64.       END;
  65.   END;
  66.   REPEAT
  67.     Move(Point1^, Point2^, ScrSze);         {copy Background for writing on}
  68.     FOR J :=1 TO MaxSpr DO BEGIN
  69.        putsprite( sprites[J] );             {virtual write to Point2}
  70.     END;
  71.     Move(point2^, mem[$a000:0000], ScrSze); {write Point2}
  72.   UNTIL KeyPressed;                         {NO retrace needed}
  73.   ASM mov ax,03h; Int 10h; END;
  74. END.
  75.  
  76.